Skip to content

STM32F1 merged (replaced by #61) #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 30 commits into from
Closed

STM32F1 merged (replaced by #61) #45

wants to merge 30 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jun 29, 2017

STM32F1 boards added. #20

The following variants are available:

  • NUCLEO-F103RB
  • DISCO-F100RB (STM32VLDISCOVERY)
  • BLUEPILL-F103C8
  • MAPLEMINI-F103CB

I tested the following features only on the Nucleo board:
ADC, PWM, I2C (master & slave), SPI, UART, Servo, Tone, EEPROM

I require some help to test the other variants and especially all upload method for BluePill and MapleMini. In advance, thank you for your help.

@ghost ghost requested a review from fpistm June 29, 2017 11:53
@fpistm fpistm added enhancement New feature or request help wanted 🙏 Extra attention is needed labels Jun 29, 2017
@rogerclarkmelbourne
Copy link

I will pull to my local repo and test later

@rogerclarkmelbourne
Copy link

rogerclarkmelbourne commented Jun 30, 2017

There are merge conflicts

cores/arduino/stm32/analog.c
cores/arduino/stm32/interrupt.c

Looking at interrupt.c, I don't know why it can't do an auto merge, it looks like you added the line

UNUSED(port);

and git doesnt like that

In analog.c its this

<<<<<<< HEAD
  if (timHandle.Instance == NP) return;
=======
  if (timHandle.Instance == NC) return;
 >>>>>>> ceff35ca1dabd4ec8b5f2d5a495a287f885771e9

So in one place you have NP and you changed it to NC

This looks like more than a typo.

Should it say NP ?

@fpistm
Copy link
Member

fpistm commented Jun 30, 2017

Right Roger,
kept the NP not NC
kept the UNUSED.

@rogerclarkmelbourne
Copy link

OK

I'll manually update, but I think you need to change interrupt.c as then it will auto merge when frederic merges it

analog.c I think frederic will need to manually merge

boards.txt Outdated
#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE'
#To enable Serial2 (USART2 on PA3, PA2) add -DENABLE_SERIAL2
#To enable Serial3 (USART3 on PB11, PB10) add -DENABLE_SERIAL3
Other_board.menu.Other_board.BLUEPILL_F103C8.build.extra_flags=-DSTM32F103xB {build.usb_flags} {build.upload_flags} -DUSBCON "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra include path should be added to platform.txt

boards.txt Outdated
#To enable HID (keyboard and mouse support) add also '-DUSBD_USE_HID_COMPOSITE'
#To enable Serial2 (USART2 on PA3, PA2) add -DENABLE_SERIAL2
#To enable Serial3 (USART3 on PB11, PB10) add -DENABLE_SERIAL3
Other_board.menu.Other_board.MAPLEMINI_F103CB.build.extra_flags=-DSTM32F103xB {build.usb_flags} {build.upload_flags} -DUSBCON "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -552,16 +558,22 @@ uint16_t adc_read_value(PinName pin)

if (AdcHandle.Instance == NC) return 0;

#ifndef STM32F1xx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a reordering of fields coul allow to have only on block define under STM32F1xx switch?

@@ -53,7 +53,10 @@
#define I2C1_EV_IRQn I2C1_IRQn

#elif defined(STM32F1xx)

#define DAC1 DAC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this define and replace DAC1 in the const PinMap PinMap_DAC[]
PeripheralPins.c by DAC

@@ -53,7 +53,10 @@
#define I2C1_EV_IRQn I2C1_IRQn

#elif defined(STM32F1xx)

#define DAC1 DAC
#define TIM15_IRQn TIM1_BRK_TIM15_IRQn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those definitions should be moved to timer.h
https://github.com/stm32duino/Arduino_Core_STM32/blob/master/cores/arduino/stm32/timer.h#L129
Only add STM32F1xx for those 3 timers IRQ

//*** DAC ***

const PinMap PinMap_DAC[] = {
{NC, NC, 0}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete empty arry

// {PB0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8
{PB1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9
// {PB1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9
{NC, NC, 0}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All
{NC, NC, 0}
have to be replace by
{NC, NP, 0}

{PC3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13
{PC4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14
{PC5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15
{NC, NC, 0}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All
{NC, NC, 0}
have to be replaced by
{NC, NP, 0}

// {PB0, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8
{PB1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9
// {PB1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9
{NC, NC, 0}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All
{NC, NC, 0}
have to be replaced by
{NC, NP, 0}

// {PC4, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14
{PC5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15
// {PC5, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15
{NC, NC, 0}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All
{NC, NC, 0}
have to be replaced by
{NC, NP, 0}

@fpistm
Copy link
Member

fpistm commented Jun 30, 2017

I think USB CDC could be more generic and available for other variant which support it.
I have already integrate a CDC on this pull:
bcmi-labs/arduino-core-stm32f4#44

I will do this stuff later. currently, I think we could kept this as it is.

@fpistm
Copy link
Member

fpistm commented Jun 30, 2017

@rogerclarkmelbourne ,
@fprwi6labs will rebase when he will update the pull with review comment.

@rogerclarkmelbourne
Copy link

One thing I noticed, because you have the BluePill and the Maple mini via a sub menu, and then have all the same upload options or both,

You end up with the original maple mini bootloader upload as the default option.

But that version of the bootloader is not available for the Blue Pill, so by default it won't work.

BTW. I have tied contacting one of the manufacturers in china who make a maple mini clone (Baite Online Store), to say they should use the new bootloader and also all their links to Leaflabs are now out of date.

But they have not been very communicative, so I don't expect they will change this :-(

@rogerclarkmelbourne
Copy link

rogerclarkmelbourne commented Jun 30, 2017

D:\Documents\Arduino\hardware\stm32duino\Arduino_Core_STM32\variants\MAPLEMINI_F103CB/variant.h:19:0: error: unterminated #ifndef

#ifndef VARIANT_ARDUINO_STM32

Edit,

My local copy may be out of date, I'm going to delete it and clone from github again

fpistm
fpistm previously approved these changes Jun 30, 2017
@@ -45,7 +45,6 @@
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
PCD_HandleTypeDef hpcd_USB_FS;
void Error_Handler(void);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To a future enhancement, maybe it should be fine to add one.

@RickKimball
Copy link
Contributor

RickKimball commented Jun 30, 2017

Native USB doesn't seem to work on a BLUEPILL-F103C8. It fails to enumerate. I get this message:

Jun 30 13:48:26 kimballr kernel: [25020.593703] usb 1-3.4: USB disconnect, device number 44
Jun 30 13:48:28 kimballr kernel: [25022.844067] usb 1-3.4: new full-speed USB device number 45 using ehci-pci
Jun 30 13:48:28 kimballr kernel: [25022.916068] usb 1-3.4: device descriptor read/64, error -32
Jun 30 13:48:28 kimballr kernel: [25023.092045] usb 1-3.4: device descriptor read/64, error -32
Jun 30 13:48:28 kimballr kernel: [25023.268066] usb 1-3.4: new full-speed USB device number 46 using ehci-pci
Jun 30 13:48:28 kimballr kernel: [25023.340070] usb 1-3.4: device descriptor read/64, error -32
Jun 30 13:48:29 kimballr kernel: [25023.516088] usb 1-3.4: device descriptor read/64, error -32
Jun 30 13:48:29 kimballr kernel: [25023.692084] usb 1-3.4: new full-speed USB device number 47 using ehci-pci
Jun 30 13:48:29 kimballr kernel: [25024.100042] usb 1-3.4: device not accepting address 47, error -32
Jun 30 13:48:29 kimballr kernel: [25024.172041] usb 1-3.4: new full-speed USB device number 48 using ehci-pci
Jun 30 13:48:30 kimballr kernel: [25024.580044] usb 1-3.4: device not accepting address 48, error -32
Jun 30 13:48:30 kimballr kernel: [25024.580190] usb 1-3-port4: unable to enumerate USB device

Using the same hardware it works fine with the libmaple core:

Jun 30 13:45:16 kimballr kernel: [24831.108039] usb 1-3.4: new full-speed USB device number 44 using ehci-pci
Jun 30 13:45:16 kimballr kernel: [24831.203456] usb 1-3.4: New USB device found, idVendor=1eaf, idProduct=0004
Jun 30 13:45:16 kimballr kernel: [24831.203462] usb 1-3.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Jun 30 13:45:16 kimballr kernel: [24831.203466] usb 1-3.4: Product: Maple
Jun 30 13:45:16 kimballr kernel: [24831.203469] usb 1-3.4: Manufacturer: LeafLabs
Jun 30 13:45:16 kimballr kernel: [24831.203913] cdc_acm 1-3.4:1.0: ttyACM1: USB ACM device
Jun 30 13:45:16 kimballr mtp-probe: checking bus 1, device 44: "/sys/devices/pci0000:00/0000:00:04.1/usb1/1-3/1-3.4"
Jun 30 13:45:16 kimballr mtp-probe: bus: 1, device: 44 was not an MTP device

I'm running ubuntu 16.04 lts, the device is actually a red pill (same as blue pill except it has the appropriate 1k5 pull up on PA12 from the manufacturer). The device is plugged into a USB 2.0 powered hub. Native USB has never been a problem on this device. It works properly with STM32CUBEMX configured as a CDC USB device. As it does with libopencm3 acting as a BMP programming device. And finally as I already mentioned libmaple CDC works fine.

Compiled for STLINK upload.

@RickKimball
Copy link
Contributor

For the BLUEPILL-F103C8 how did you decide to map the pins? They don't match the way the pins are laid out nor do they match the original libmaple simple scheme.

@fpistm fpistm dismissed their stale review June 30, 2017 19:20

Wait another feedback

@ghost
Copy link
Author

ghost commented Jul 3, 2017

@RickKimball I reordered the pin mapping of the BluePill following the old variant.h from the repository STM32F1. I don't know why I didn't copy it before.
Could you confirm me that is the good one now?

I found my BluePill board so I will check the Native USB.

@RickKimball
Copy link
Contributor

RickKimball commented Jul 3, 2017

Regarding the USB not working.

The BLUEPILL boards don't actually have a USB_DISC_PIN. To simulate a USB reset sequence, we have been setting the USBD+ pinmode to an output, setting the pin low, delaying for the usb reset period then setting the mode back to an input so that the pull up resistor pulls the pin high. Then the nomal USB init sequence is run. The code as written seems to expect a real USB_DISC_PIN that would have an NPN transistor. The BLUE PILL does not have any hardware like that.

Sample of what you might do

$ git diff cores/arduino/USBSerial.cpp variants/BLUEPILL_F103C8/variant.h
diff --git a/cores/arduino/USBSerial.cpp b/cores/arduino/USBSerial.cpp
index 93b74c0..70ccc01 100644
--- a/cores/arduino/USBSerial.cpp
+++ b/cores/arduino/USBSerial.cpp
@@ -43,9 +43,15 @@ void USBSerial::init(void){
 
 #ifdef USB_DISC_PIN
   pinMode(USB_DISC_PIN, OUTPUT);
-  digitalWrite(USB_DISC_PIN, HIGH);
-       for(i=0;i<512;i++);
-  digitalWrite(USB_DISC_PIN, LOW);
+ #if USB_DISC_PIN == USBDPLUS_PIN
+  digitalWrite(USB_DISC_PIN, LOW);  /* drag PA12 low */
+  for(i=0;i<512;i++);
+  pinMode(USB_DISC_PIN, INPUT);     /* let it float up */
+ #else
+  digitalWrite(USB_DISC_PIN, HIGH); /* trigger npn */
+  for(i=0;i<512;i++);
+  digitalWrite(USB_DISC_PIN, LOW);  /* untrigger npn */
+ #endif
 #else
   #error "USB_DISC_PIN definition missing"
 #endif
 
diff --git a/variants/BLUEPILL_F103C8/variant.h b/variants/BLUEPILL_F103C8/variant.h
index 08bba93..0d7955f 100644
--- a/variants/BLUEPILL_F103C8/variant.h
+++ b/variants/BLUEPILL_F103C8/variant.h
@@ -107,6 +107,7 @@ enum {
 
 #if defined(SERIAL_USB) && defined(USBCON)
 #define USB_DISC_PIN 12 //PA12 = USB Plus (+) pin number. That pin is normally pulled up to 3.3v by a 1.5k resistor
+#define USBDPLUS_PIN 12 //
 #endif
 
 #ifdef __cplusplus

@rogerclarkmelbourne
Copy link

I recently had to make a change about this in libmaple

USB_DISC port and pin were defined in board.txt and passed as defined to the compiler.

So I changed the code so that if either of these were null, the code to init and toggle this pin were not executed.

There is a separate define in LibMaple which is also used to toggle USBD+, but I should probably change it, so that the define for USB_DISC port or pin being null is used instead

This does also assume that USB_SERIAL is defined (so that the code knows that USB serial should be compiled in)

@Testato
Copy link
Contributor

Testato commented Jul 4, 2017

excuse the intrusion, but i'm here only for remember that Bluepill is the most important variant for the success of this core.
Every maker on every group start he's adventure on ST by a Bluepill.
So it is very important that the upload, the bootloader, etc work simple, at least like on the Roger Arduino_STM32

@danieleff
Copy link

  1. You need to let the build.txt parameter VECT_TAB_OFFSET to override the default
--- a/system/STM32F1xx/system_stm32f1xx.c
+++ b/system/STM32F1xx/system_stm32f1xx.c
@@ -110,8 +110,10 @@
 /*!< Uncomment the following line if you need to relocate your vector Table in
      Internal SRAM. */ 
 /* #define VECT_TAB_SRAM */
+#ifndef VECT_TAB_OFFSET
 #define VECT_TAB_OFFSET  0x0 /*!< Vector Table base offset field. 
                                   This value must be a multiple of 0x200. */
+#endif
  1. USB_LP_CAN1_RX0_IRQHandler is needed, either in variants/usb/....c, or USBSerial.cpp
void USB_LP_CAN1_RX0_IRQHandler(void) {
    HAL_PCD_IRQHandler(&hpcd_USB_FS); 
}

@rogerclarkmelbourne
Copy link

rogerclarkmelbourne commented Jul 4, 2017

I thought we had already added bootloader uploads to the old F1 repo.

One of the files ( headers ) in the HAL had to be mofied, as it did not allow overriding of the vector table offset, but this may have been fixed in newer versions of the Cube, because I know that the Cube HAL files for some other MCUs ,e g the F4 did not need to be modified as they already had the guard , ifdefs around the vector table define.

The linker also needs to be changed to support using the bootloader

@RickKimball
Copy link
Contributor

RickKimball commented Jul 4, 2017

USB_LP_CAN1_RX0_IRQHandler is needed, either in variants/usb/....c, or USBSerial.cpp
void USB_LP_CAN1_RX0_IRQHandler(void) {
HAL_PCD_IRQHandler(&hpcd_USB_FS);
}

This gets it to enumerate, thanks! Now to figure out why it isn't spewing data. ...

@rogerclarkmelbourne
Copy link

Rick did you change system_stm32f1xx.c

to match whats in the old F1 repo
e.g. add the guard ifdef

https://github.com/stm32duino/Arduino_Core_STM32F1/blob/25671e086825821eeeb50d903a6c293fce6515e3/cores/arduino/libstm32f1/system_stm32f1xx.c#L113-L116

@RickKimball
Copy link
Contributor

I didn't.I'm using it with an stlink.

@fpistm
Copy link
Member

fpistm commented Jul 5, 2017

@Testato
excuse the intrusion, but i'm here only for remember that Bluepill is the most important variant for the success of this core.
Every maker on every group start he's adventure on ST by a Bluepill.
So it is very important that the upload, the bootloader, etc work simple, at least like on the Roger Arduino_STM32

If a core include a variant this is to be functional...
Any help are welcome

@RickKimball
Copy link
Contributor

@fprwi6labs

@RickKimball I reordered the pin mapping of the BluePill following the old variant.h from the repository STM32F1. I don't know why I didn't copy it before.
Could you confirm me that is the good one now?

Yes the digital pins seem to work fine:

unsigned nextpin = 0;
unsigned long previousMillis = 0;        // will store last time LED was updated
unsigned ledState;

void displayPinInfo(unsigned index) {
  unsigned p = digitalPin[index];
  unsigned port = p >> 4 & 0x0f;
  unsigned pin = p & 0xf;

  Serial.print("PIN "); Serial.print(index); Serial.print(" = P"); Serial.print("ABCDEF"[port]); Serial.println(pin);

}

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println("Digital Pin Test\r\nPress enter to go to next pin");
  pinMode(nextpin, OUTPUT);
  displayPinInfo(nextpin);
}


void loop() {
  if ( Serial.available() ) {
    int c = Serial.read();

    pinMode(nextpin, INPUT);
    nextpin++;
    switch (nextpin) {
      case 11: // skip USB pins
      case 12:
        nextpin = 13;
        break;
      case 35:
        nextpin = 0;
        break;
    }

    pinMode(nextpin, OUTPUT);
    displayPinInfo(nextpin);
  }

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= 100) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    digitalWrite(nextpin, ledState);
    ledState ^= 1;
  }

}

fpr and others added 21 commits July 11, 2017 14:48
Upload method Bootloader, Serial and BMP added.
USBSerial class added because is required by bootloader.

Signed-off-by: fpr <[email protected]>
Signed-off-by: Frederic.Pillon <[email protected]>
Signed-off-by: Frederic.Pillon <[email protected]>
Remove STLink Rx/TX from Ax and comment in PinMap arrays
other than UARTyx one.

Signed-off-by: Frederic.Pillon <[email protected]>
@fpistm
Copy link
Member

fpistm commented Jul 11, 2017

First part merged: #60
Second part will be added soon: #61

@fpistm
Copy link
Member

fpistm commented Jul 11, 2017

Please make further comment on this PR: #61

@fpistm fpistm added invalid This doesn't seem right and removed help wanted 🙏 Extra attention is needed labels Aug 16, 2017
@fpistm fpistm changed the title STM32F1 merged STM32F1 merged (replaced by #61) Aug 18, 2017
@fpistm fpistm closed this Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants